import {request} from "../../network/index";

Page({
  /**
   * 页面的初始数据
   */
  data: {
    banner:[],
    tabIcon:[],
    recommend:[],
    toplist:[],
    redio:[],
    MV:[]
  },
  toTabbar(){
    wx.switchTab({
      url: '/pages/radio/radio',
    })
  },
  toDetailRadio(event){
    wx.switchTab({
      url: '/pages/radio/radio',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function(options) {    
      request('/banner',{type:1}).then(bannerData => {
        this.setData({
          banner:bannerData.data.banners,
        })
      })
      request('/homepage/dragon/ball').then(tabIcon => {
        this.setData({
          tabIcon:tabIcon.data.data,
        })
      })
      request('/personalized',{limit:6}).then(recommend => {
        this.setData({
          recommend:recommend.data.result,
        })
      })

      request('/toplist/detail').then(toplist => {
        this.setData({
          toplist:toplist.data.list.slice(0,4),
        })
      })
      request('/personalized/djprogram').then(redio => {
        this.setData({
          redio:redio.data.result,
        })
      })
      let MV = await request('/personalized/mv')
      this.setData({
        MV:MV.data.result
      })
  },
  //轮播图点击事件
  toPlayMusic(event){
     let id = event.currentTarget.dataset.id
     wx.navigateTo({
       url: `/pages/songDetail/songDetail?id=${id}`,
     })
  },
  //点击tab图标
  toDetail(event){
    let id = event.currentTarget.dataset.id
    console.log(id);
    if(id === 0){
      wx.navigateTo({
        url: '/pages/recommendSongs/recommendSongs',
      })
    }else if(id === 1){
      request('/personal_fm').then(result=>{
        wx.navigateTo({
          url: '/pages/musicPlayer/musicPlayer',
          success(res){
            res.eventChannel.emit('getMusicData',result)
          }
        })     
      })
    }else if(id === 2){
      wx.navigateTo({
        url: '/pages/musicMenuPlaza/musicMenuPlaza',
      })
    }else if(id === 3){
      wx.navigateTo({
        url: '/pages/topList/topList',
      })
    }else{
      wx.showToast({
        title: '暂未开发',
      })
    }
  },
  toSearch(){
    wx.navigateTo({
      url: '/pages/search/search',
    })
  },
  //推荐歌单详情
  musicRecommend(event){
  let id = event.currentTarget.dataset.id
    
   wx.navigateTo({
     url: `/pages/musciListDetial/musciListDetial?id=${id}`
   })
  },
  toMusicListDetail(event){
    let id = event.currentTarget.dataset.id
		wx.navigateTo({
			url: `/pages/musciListDetial/musciListDetial?id=${id}`
		})
  },
  toMvDetail(event){
    let id = event.currentTarget.dataset.id
    console.log(id);
    wx.navigateTo({
      url: `/pages/mvPlay/mvPlay?id=${id}`,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady:async function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})